package cn.jiyun.config;

import cn.jiyun.converter.DateConverter;
import cn.jiyun.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类  将自定义日期转换器交由spring容器管理
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        //将自定义日期转换器交由spring容器管理
        registry.addConverter(new DateConverter());
    }

    //将自定义拦截器交由springmvc容器管理
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addPathPatterns 配置拦截的路径规则
        //excludePathPatterns 配置不拦截的路径规则
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/login");
    }
}
